package top.yongyan0624.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import org.springframework.beans.factory.annotation.Autowired;
import top.yongyan0624.entity.Leader;
import top.yongyan0624.entity.LeaderDesc;
import top.yongyan0624.mapper.LeaderMapper;
import top.yongyan0624.service.LeaderDescService;
import top.yongyan0624.service.LeaderService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author yongyan
 * @since 2021-05-17
 */
@Service
public class LeaderServiceImpl extends ServiceImpl<LeaderMapper, Leader> implements LeaderService {

    @Autowired
    private LeaderDescService leaderDescService;

    @Override
    public List<Leader> leader() {
        List<Leader> leaders = this.list();

        for (Leader leader : leaders) {
            List<LeaderDesc> descList = leaderDescService.list(new QueryWrapper<LeaderDesc>()
                    .inSql("id", "select id from leader_desc where leader_id = " + leader.getId()));
            String[] desc = descList.stream().map(LeaderDesc::getName).toArray(String[]::new);
            leader.setDesc(desc);
        }

        return leaders;
    }
}
